<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>forEach</title>
</head>

<body>
  <script>
    console.log('------------forEach----------------');

    var arr = ['a', 'c', 'b', 'd', 'e', 'f', 'g'];
    arr.forEach(function (item, index) {
      console.log(item + ',' + index);
    })

    console.log('------------map----------------');
    var result = arr.map(function (item, index) {
      return index + item;
    })
    console.log(result);

    console.log('-----------sort会改变原来的数组---------------');
    arr2 = [1, 4, 3, 2, 6, 77, 32];
    result = arr2.sort((a, b) => {
      return a - b;
    })
    console.log(result);
    
    console.log('-------------filter 过滤符合条件的元素---------------');
    result = arr2.filter(function (item, index) {
      if (item > 10) {
        return true;
      }
    })
    console.log(result);

    console.log('------------every 判断是否所有元素都符合要求 返回t or f----------------');
    result = arr2.every(function (item , index){
      if (item >= 10 ) {
        return true;
      }
    })
    console.log(result);


    console.log('--------------some 判断是否有元素满足条件 返回 t or f---------------');
    result = arr2.every(function (item , index){
      if (item >= 1 ) {
        return true;
      }
    })
    console.log(result);

    console.log('-------------join（根据条件对数组组合成字符串）不会改变原数组-------------');
    result = arr2.join('+');
    console.log(result);
    console.log(arr2);

    console.log('-------------reverse（将数组反转）会改变原数组-------------');
    result = arr2.reverse();
    console.log(result);
    console.log(arr2 );

  </script>
</body>

</html>